package com.zzptc.zzsgz.bdsjws.activities;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.fragments.Fragment_family1;
import com.zzptc.zzsgz.bdsjws.fragments.Fragment_family2;

import butterknife.BindView;
import butterknife.OnClick;

public class OneKeySOSActivity extends BaseActivity {

    @BindView(R.id.toolbar_sos)
    Toolbar toolbarSos;
    @BindView(R.id.frame)
    FrameLayout frame;
    Fragment_family1 fragment_family1;
    @BindView(R.id.Id_sos)
    ImageView IdSos;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public int getContentXML() {
        return R.layout.activity_one_key_sos;
    }

    @Override
    public void initData() {

    }

    @Override
    public void intView() {
        setSupportActionBar(toolbarSos);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        //加载Fragment
        if (fragment_family1 == null) {
            fragment_family1 = new Fragment_family1();
        }
        getFragmentManager()
                .beginTransaction()
                .replace(R.id.frame, fragment_family1).addToBackStack("sos").commit();
    }

    public void totwoFragment() {
        getFragmentManager()
                .beginTransaction()
                .hide(fragment_family1)
                .add(R.id.frame, new Fragment_family2())
                .addToBackStack("sos")
                .commit();
        //让图标消失 在回退时再显示
        IdSos.setVisibility(View.GONE);
    }

    //解决回退异常
    @Override
    public void onBackPressed() {
        if (getFragmentManager().getBackStackEntryCount() > 1) {
            getFragmentManager().popBackStack();
            IdSos.setVisibility(View.VISIBLE);
        } else {
            finish();

        }

    }

    @OnClick(R.id.Id_sos)
    public void onViewClicked() {
    }
}
